#ifndef H_RTMP_PUSHER_H
#define H_RTMP_PUSHER_H
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
#include <libavdevice/avdevice.h>
#include <libavformat/version.h>
#include <libavutil/time.h>
#include <libavutil/mathematics.h>
#include "libavutil/audio_fifo.h"
#include "libavutil/mathematics.h"
#include "libswresample/swresample.h"
}

class CRtmpPusher
{
public:
	CRtmpPusher();
	~CRtmpPusher();

	bool InitPusher();
	void Frame();
private:
	AVFormatContext * ifmt_ctx_a = NULL;
	AVFormatContext *ifmt_ctx = NULL;
	AVFormatContext *ofmt_ctx;
	AVInputFormat* ifmt;
	AVStream* video_st;
	AVStream* audio_st;
	AVCodecContext* pCodecCtx;
	AVCodecContext* pCodecCtx_a;
	AVCodec* pCodec;
	AVCodec* pCodec_a;
	AVPacket *dec_pkt, enc_pkt;
	AVPacket *dec_pkt_a, enc_pkt_a;
	AVFrame *pframe, *pFrameYUV;
	uint8_t *out_buffer;
	struct SwsContext *img_convert_ctx;
	struct SwrContext *aud_convert_ctx;

	int framecnt = 0;
	int nb_samples = 0;
	int videoindex;
	int audioindex;
	int i;
	int ret;

	// const char* out_path = "rtmp://localhost/live/AE581";  // "rtmp://localhost/live/livestream";
	int dec_got_frame, enc_got_frame;
	int dec_got_frame_a, enc_got_frame_a;

	int aud_next_pts = 0;
	int vid_next_pts = 0;
	int encode_video = 1, encode_audio = 1;

	AVRational time_base_q = { 1, AV_TIME_BASE };

	int64_t start_time;
	AVAudioFifo *fifo = NULL;
	uint8_t **converted_input_samples = NULL;
	AVPacket pkt;
};
#endif // !H_RTMP_PUSHER_H
